package com.yyy.controller;

import com.yyy.entity.Passenger;
import com.yyy.entity.Pnr;
import com.yyy.service.PassengerService;
import com.yyy.service.PnrService;
import com.yyy.service.TicketInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by admin on 2018/8/7.
 */
@Controller
@RequestMapping(value = "/base")
public class BaseController {
    @Resource
    private PassengerService passengerService;

    @Resource
    private TicketInfoService ticketInfoService;

    @Resource
    private PnrService pnrService;

    @RequestMapping(path = "/passenger/query")
    @ResponseBody
    public Object passengerQueryV2(final String name, final String cardNo) {
        return passengerService.findByNameLikeAndCardNum(name.concat("%"), cardNo);
    }

    @RequestMapping(path = "/passenger/queryBySpecification")
    @ResponseBody
    public Object passengerSpecification(String type, String issueOfficeCode) {
        final Passenger passenger = new Passenger();
        passenger.setType(type);
        Pnr pnr = new Pnr();
        pnr.setIssueOfficeCode(issueOfficeCode);
        passenger.setPnr(pnr);
        return passengerService.findBySpecification(passenger);
    }

    @RequestMapping(path = "/pnr/findAll")
    @ResponseBody
    public Object pnrFindAll(int page, int pageSize) {
        return pnrService.findAll(page, pageSize);
    }

    @RequestMapping(path = "/ticket/group")
    @ResponseBody
    public Object ticketGroup() {
        return ticketInfoService.createCriteriaQuery();
    }
}
